Skip to content

fix: limit decompressed webhook payloads to 10 MiB - #246

Merged
mogita merged 2 commits into
masterfrom
fix/webhook-gzip-limit
Nov 16, 2026
Merged

mogita merged 2 commits into
masterfrom
fix/webhook-gzip-limit

Conversation

@mogita

@mogita mogita commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Submit a pull request

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

Problem

gunzip_payload inflated a gzip body with no size limit before the signature check, so an unsigned request of a few hundred KB could expand to hundreds of MB and exhaust memory on a webhook endpoint.

Solution

Decompression now stops at 10 MiB and raises InvalidWebhookError ("gzip decompression failed: payload exceeds 10485760 bytes"). The same helper backs verify_and_parse_webhook, parse_sqs and parse_sns. Raise the cap if your events are larger:

import stream_chat.webhook

stream_chat.webhook.MAX_WEBHOOK_PAYLOAD_BYTES = 50 * 1024 * 1024

Uncompressed bodies are not limited, and multi-member gzip still inflates as before. Corrupt deflate data now raises InvalidWebhookError instead of leaking zlib.error. This matches the default and error message of the other server SDKs.

How to verify

  1. pytest stream_chat/tests/test_webhook_compression.py (passes locally on Python 3.8 and 3.12).
  2. The new tests inflate a body of exactly 10 MiB, reject 10 MiB + 1 byte through verify_and_parse_webhook and parse_sqs, and honour a custom limit.

Note

Medium Risk
Changes webhook ingestion before HMAC verification and rejects oversized gzip, which could break unusually large legitimate events unless the cap is raised.

Overview
Gzip webhook decompression is now bounded at 10 MiB via a new MAX_WEBHOOK_PAYLOAD_BYTES setting on stream_chat.webhook, because gunzip_payload runs before signature verification and could previously be abused with gzip bombs.

Decompression switches from gzip.decompress to a capped GzipFile.read(limit + 1) flow. Oversized output raises InvalidWebhookError with a payload exceeds … bytes message; corrupt deflate data is mapped to the same webhook error (including zlib.error). Uncompressed bodies and multi-member gzip behavior are unchanged, and the limit is tunable by assigning webhook.MAX_WEBHOOK_PAYLOAD_BYTES.

Tests cover the 10 MiB boundary, gzip-bomb rejection through verify_and_parse_webhook and parse_sqs, corrupt streams, multi-member inflation, and a monkeypatched custom cap.

Reviewed by Cursor Bugbot for commit 6322de6. Bugbot is set up for automated code reviews on this repo. Configure here.

gunzip_payload runs before the signature check, so an unsigned gzip bomb could exhaust memory. Decompression now stops at MAX_WEBHOOK_PAYLOAD_BYTES (default 10 MiB) and raises InvalidWebhookError. Corrupt deflate data now raises InvalidWebhookError instead of zlib.error.
@mogita
mogita merged commit 7ba4932 into master Nov 16, 2026
14 of 16 checks passed
@mogita
mogita deleted the fix/webhook-gzip-limit branch November 16, 2026 14:26
@mogita mogita mentioned this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant